package com.plian.system.service.glcydgz.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.plian.Tools.*;
import com.plian.Tools.pagedata.PageData;
import com.plian.system.constant.sys.FormStatusConstant;
import com.plian.system.constant.sys.FormTypeConstant;
import com.plian.system.dto.pf.BaseBusinessAuditDTO;
import com.plian.system.entity.pf.*;
import com.plian.system.entity.sys.Message;
import com.plian.system.mapper.pf.BaseBusinessAuditMapper;
import com.plian.system.mapper.pf.SelfAssessmentMapper;
import com.plian.system.model.CommonCode;
import com.plian.system.model.R;
import com.plian.system.mybatis.base.BaseFlowService;
import com.plian.system.mybatis.base.BaseServiceImpl;
import com.plian.system.service.glc.IGlcBaseBusinessIndicatorsService;
import com.plian.system.service.glcydgz.IGlcBaseBusinessAnnualService;
import com.plian.system.service.glcydgz.IGlcBaseBusinessAuditService;
import com.plian.system.service.pf.*;
import com.plian.system.service.sys.code.IFormCodeService;
import com.plian.system.service.sys.message.IMessageService;
import com.plian.system.service.sys.orgzation.IOrgService;
import com.plian.system.service.sys.user.ISysUserService;
import com.plian.system.service.wf.FormWorkflowService;
import com.plian.system.vo.pf.*;
import com.plian.system.wrapper.pf.*;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;

import static com.plian.system.constant.sys.FormStatusConstant.UNREVIEWED;

/**
 * @Author: Take-off
 * @Description: TODO 经营业绩考核国资审核 服务实现类
 * @Date: 2022/12/19 9:32 AM
 * @Version: 1.0
 **/
@Slf4j
@Service
@AllArgsConstructor
public class GlcBaseBusinessAuditServiceImpl extends BaseServiceImpl<BaseBusinessAuditMapper, BaseBusinessAudit> implements IGlcBaseBusinessAuditService, BaseFlowService {

    private FormWorkflowService formWorkflowService;

    private IFormCodeService formCodeService;

    private BaseBusinessAuditWrapper baseBusinessAuditWrapper;

    private IBusinessAuditService businessAuditService;

    private BusinessAuditWrapper businessAuditWrapper;

    private ITaskAuditService taskAuditService;

    private TaskAuditWrapper taskAuditWrapper;

    private IGlcBaseBusinessIndicatorsService glcBaseBusinessIndicatorsService;

    private BaseBusinessIndicatorsWrapper baseBusinessIndicatorsWrapper;

    private IGlcBaseBusinessAnnualService glcBaseBusinessAnnualService;

    private IAuditAssetsService auditAssetsService;

    private IMainAuditService mainAuditService;

    private MainAuditWrapper mainAuditWrapper;

    private IMessageService messageService;

    private IOrgService orgService;

    private ISysUserService userService;

    private SelfAssessmentMapper selfAssessmentMapper;

    @Override
    public boolean saveOrUpdate(BaseBusinessAudit baseBusinessAudit) {
        baseBusinessAudit.setModuleType(1);
        if (!Optional.ofNullable(baseBusinessAudit.getStatus()).isPresent()) {
            baseBusinessAudit.setStatus(FormStatusConstant.UNREVIEWED);
        }
        if (baseBusinessAudit.getStatus().equals(FormStatusConstant.REJECT)) {
            baseBusinessAudit.setStatus(FormStatusConstant.UNREVIEWED);
        }
        if (!Optional.ofNullable(baseBusinessAudit.getId()).isPresent()) {
            baseBusinessAudit.setCode(formCodeService.getCode(FormTypeConstant.GLC_BUSINESS_AUDIT));
            baseBusinessAudit.setFormType(String.valueOf(FormTypeConstant.GLC_BUSINESS_AUDIT));
        }
        if (!Optional.ofNullable(baseBusinessAudit.getIssued()).isPresent()) {
            baseBusinessAudit.setIssued(0);
        }
        return super.saveOrUpdate(baseBusinessAudit);
    }

    @Override
    @Transactional(rollbackFor=RuntimeException.class)
    public boolean deleteLogic(List<Long> ids) {
        for (Long id : ids) {
            BaseBusinessAudit baseBusinessAudit = getById(id);
            if (baseBusinessAudit == null) {
                return false;
            } else if (baseBusinessAudit.getStatus() != null &&
                    (baseBusinessAudit.getStatus() != FormStatusConstant.STASH && baseBusinessAudit.getStatus() != FormStatusConstant.UNREVIEWED)) {
                return false;
            }
            formWorkflowService.deleteProcessInstance(String.valueOf(id));
        }

        boolean result = super.deleteLogic(ids);
        if (result){
            businessAuditService.deleteByParentId(ids);
            taskAuditService.deleteByParentId(ids);
            mainAuditService.deleteByParentId(ids);
            auditAssetsService.deleteByParentId(ids);
        }
        return result;
    }


    @Override
    public HashMap<String,Object> commit(String id) {
        handleStatus(Long.valueOf(id), FormStatusConstant.FLOW);

        //将需要提交的流程变量返回，用于工作流侧
        return new HashMap<String,Object>();
    }

    @Override
    public Boolean finish(String id) {
        Boolean result = handleStatus(Long.valueOf(id), FormStatusConstant.FINISH);
        return result;
    }

    @Override
    public Boolean reject(String id, int formState, String comment) {
        return handleStatus(Long.valueOf(id), formState);
    }


    @Override
    public List<PageData> findByIds(List<String> formIds) {
        LambdaQueryWrapper<BaseBusinessAudit> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(BaseBusinessAudit::getId, Func.toLongList(StringUtils.join(formIds, StringPool.COMMA)));
        queryWrapper.eq(BaseBusinessAudit::getModuleType,1);
        List<BaseBusinessAudit> baseBusinessAudits = list(queryWrapper);
        List<BaseBusinessAuditVO> baseBusinessAuditVOS = baseBusinessAuditWrapper.entityToVO(baseBusinessAudits);
        List<PageData> pageDataList = new ArrayList<>();
        try{
            if (CollectionUtil.isNotEmpty(baseBusinessAuditVOS)){
                for (BaseBusinessAuditVO vo : baseBusinessAuditVOS){
                    PageData pd = new PageData();
                    pd.put("id", vo.getId());
                    pd.put("UNITNAME", vo.getFillingUnitName());
                    pd.put("APPLICANTNAME", vo.getCreateUserName());
                    pd.put("applicantId", vo.getCreateUser());
                    pd.put("applyOrganizationId", vo.getFillingUnitId());
                    pd.put("formType", FormTypeConstant.GLC_BUSINESS_AUDIT);
                    pd.put("orgName", vo.getFillingUnitName());
                    pageDataList.add(pd);
                }
            }

            return pageDataList;
        } catch (Exception e) {
            log.error(ExceptionUtils.getFullStackTrace(e));
        }
        return pageDataList;
    }

    @Override
    public List<Integer> getFormType() {
        return Arrays.asList(FormTypeConstant.GLC_BUSINESS_AUDIT);
    }


    @Override
    public void goBackToStash(String formId) {
        handleStatus(Long.valueOf(formId), UNREVIEWED);
    }

    /**
     * 统一处理状态机事件方法
     *
     * @param id          主键
     * @param updateStatus  更新状态
     * @return boolean
     */
    private Boolean handleStatus(Long id, int updateStatus) {
        try {
            BaseBusinessAudit baseBusinessAudit = getById(id);
            /**
             * 设置审批人和审批时间
             */
            if (updateStatus == FormStatusConstant.FINISH){
                baseBusinessAudit.setApprovedUser(TokenUtil.getTokenUserId());
                Date now = DateUtil.now();
                baseBusinessAudit.setApprovedTime(now);
            }
            baseBusinessAudit.setStatus(updateStatus);
            updateById(baseBusinessAudit);
            return true;
        } catch (Exception e) {
            log.error(ExceptionUtils.getFullStackTrace(e));
            return false;
        }
    }

    @Override
    public String checkYear(BaseBusinessAudit baseBusinessAudit) {
        String fillingYear = baseBusinessAudit.getFillingYear();
        String fillingUnitId = baseBusinessAudit.getFillingUnitId();
        QueryWrapper<BaseBusinessAudit> queryWrapper = new QueryWrapper<>();
        if (!Optional.ofNullable(fillingYear).isPresent()) {
            return "填报时间为空";
        }
        if (!Optional.ofNullable(fillingUnitId).isPresent()){
            return "填报单位为空";
        }
        //判断该时间的基础表
        List<BaseBusinessIndicators> baseBusinessIndicators = glcBaseBusinessIndicatorsService.list(new LambdaQueryWrapper<BaseBusinessIndicators>().eq(BaseBusinessIndicators::getStatus, 3)
                .eq(BaseBusinessIndicators::getFillingYear, fillingYear).eq(BaseBusinessIndicators::getFillingUnitId, fillingUnitId)
                .eq(BaseBusinessIndicators::getModuleType,2));
        if (CollectionUtil.isEmpty(baseBusinessIndicators)){
            return "该年度基础表没填";
        }
        queryWrapper.eq("filling_unit_id", fillingUnitId);
        queryWrapper.eq("filling_year", fillingYear);
        queryWrapper.eq("module_type",1);
        BaseBusinessAudit one = getOne(queryWrapper);
        if (!Optional.ofNullable(one).isPresent()){
            return null;
        }
        if (one.getId().equals(baseBusinessAudit.getId())){
            return null;
        }
        return "该年度已填报";
    }

    @Override
    @Transactional(rollbackFor=RuntimeException.class)
    public boolean submit(BaseBusinessAudit baseBusinessAudit) {
        boolean result = saveOrUpdate(baseBusinessAudit);
        if (result){
            List<BusinessAudit> businessAudits = baseBusinessAudit.getBusinessAudits();
            if (CollectionUtil.isNotEmpty(businessAudits)){
                for (BusinessAudit businessAudit : businessAudits){
                    if (businessAudit.getId() != null &&
                            Optional.ofNullable(businessAudit.getIsDeleted()).isPresent() && businessAudit.getIsDeleted().intValue() == 1) {
                        businessAuditService.removeById(businessAudit.getId());
                    }else {
                        businessAudit.setBaseBusinessAuditId(baseBusinessAudit.getId());
                        businessAuditService.saveOrUpdate(businessAudit);
                    }
                }
            }
            List<TaskAudit> taskAudits = baseBusinessAudit.getTaskAudits();
            if (CollectionUtil.isNotEmpty(taskAudits)){
                for (TaskAudit taskAudit : taskAudits){
                    if (taskAudit.getId() != null &&
                            Optional.ofNullable(taskAudit.getIsDeleted()).isPresent() && taskAudit.getIsDeleted().intValue() == 1) {
                        taskAuditService.removeById(taskAudit.getId());
                    }else {
                        taskAudit.setBaseBusinessAuditId(baseBusinessAudit.getId());
                        taskAuditService.saveOrUpdate(taskAudit);
                    }
                }
            }

            List<MainAudit> mainAudits = baseBusinessAudit.getMainAudits();
            if (CollectionUtil.isNotEmpty(mainAudits)){
                for (MainAudit mainAudit : mainAudits){
                    if (mainAudit.getId() != null &&
                            Optional.ofNullable(mainAudit.getIsDeleted()).isPresent() && mainAudit.getIsDeleted().intValue() == 1) {
                        mainAuditService.removeById(mainAudit.getId());
                    }else {
                        mainAudit.setBaseBusinessAuditId(baseBusinessAudit.getId());
                        mainAuditService.saveOrUpdate(mainAudit);
                    }
                }
            }

            List<AuditAssets> auditAssets = baseBusinessAudit.getAuditAssets();
            if (CollectionUtil.isNotEmpty(auditAssets)){
                for (AuditAssets auditAsset : auditAssets){
                    if (auditAsset.getId() != null &&
                            Optional.ofNullable(auditAsset.getIsDeleted()).isPresent() && auditAsset.getIsDeleted().intValue() == 1) {
                        auditAssetsService.removeById(auditAsset.getId());
                    }else {
                        auditAsset.setBaseBusinessAuditId(baseBusinessAudit.getId());
                        auditAssetsService.saveOrUpdate(auditAsset);
                    }
                }
            }

        }
        return result;
    }

    @Override
    public R<BaseBusinessAuditVO> getDetailObj(BaseBusinessAuditVO baseBusinessAuditVO) {
        if(!Optional.ofNullable(baseBusinessAuditVO).isPresent()){
            return new R(CommonCode.FAIL);
        }

        //年度审核数据
        BaseBusinessAnnualVO detailByBase = glcBaseBusinessAnnualService.getDetailByBase(baseBusinessAuditVO.getFillingYear(), baseBusinessAuditVO.getFillingUnitId());

        //财务绩效
        List<BusinessAuditVO> businessAuditVOS = businessAuditWrapper
                .entityToVO(businessAuditService.list(new LambdaQueryWrapper<BusinessAudit>()
                        .eq(BusinessAudit::getBaseBusinessAuditId, baseBusinessAuditVO.getId())));
        setBusinessProgress(businessAuditVOS,detailByBase.getBusinessAnnualVOS());
        baseBusinessAuditVO.setBusinessAuditVOS(businessAuditVOS);

        //任务绩效
        List<TaskAuditVO> taskAuditVOS = taskAuditWrapper
                .entityToVO(taskAuditService.list(new LambdaQueryWrapper<TaskAudit>()
                        .eq(TaskAudit::getBaseBusinessAuditId, baseBusinessAuditVO.getId())));
        setTaskProgress(taskAuditVOS,detailByBase.getTaskAnnualVOS());
        baseBusinessAuditVO.setTaskAuditVOS(taskAuditVOS);
        //重大工程
        baseBusinessAuditVO.setMajorProgressVOS(detailByBase.getMajorProgressVOS());
        //主责主业
        List<MainAuditVO> mainAuditVOS = mainAuditWrapper
                .entityToVO(mainAuditService.list(new LambdaQueryWrapper<MainAudit>()
                        .eq(MainAudit::getBaseBusinessAuditId, baseBusinessAuditVO.getId())));
        setMainAudit(mainAuditVOS,detailByBase.getMainAnnualVOS());
        baseBusinessAuditVO.setMainAuditVOS(mainAuditVOS);
        //履职成效
        baseBusinessAuditVO.setEffectiveRate(detailByBase.getEffectiveRate());
        baseBusinessAuditVO.setTargetValue(detailByBase.getTargetValue());
        baseBusinessAuditVO.setRemarks(detailByBase.getRemarks());
        baseBusinessAuditVO.setIsMajorProject(detailByBase.getIsMajorProject());
        //企业自评
        List<AuditAssets> auditAssets = auditAssetsService.list(new LambdaQueryWrapper<AuditAssets>().eq(AuditAssets::getBaseBusinessAuditId, baseBusinessAuditVO.getId()));
        setAuditAssets(auditAssets,detailByBase.getSelfAssessments());
        baseBusinessAuditVO.setAuditAssets(auditAssets);

        R<BaseBusinessAuditVO> objResult = new R<>(CommonCode.SUCCESS);
        objResult.setPageData(baseBusinessAuditVO);
        return objResult;
    }

    /**
     * @Author: Take-off
     * @Description: //TODO 根据年度和企业获取基础表
     * @Date: 10:56 AM 2022/12/16
     * @Param: [dto]
     * @return: com.plian.system.vo.pf.BaseBusinessProgressVO
     **/
    @Override
    public BaseBusinessAuditVO getDetailByDto(BaseBusinessAuditDTO dto){
        BaseBusinessAuditVO baseBusinessAuditVO = new BaseBusinessAuditVO();
        //年度审核数据
        BaseBusinessAnnualVO detailByBase = glcBaseBusinessAnnualService.getDetailByBase(dto.getFillingYear(), dto.getFillingUnitId());

        //财务绩效
        if (Optional.ofNullable(detailByBase).isPresent()){
            //主表Id
            baseBusinessAuditVO.setBaseBusinessIndicatorsId(detailByBase.getBaseBusinessIndicatorsId());
            //财务绩效
            List<BusinessAuditVO> businessAuditVOS = new ArrayList<>();
            setBusinessProgress(businessAuditVOS,detailByBase.getBusinessAnnualVOS());
            baseBusinessAuditVO.setBusinessAuditVOS(businessAuditVOS);

            //任务绩效
            List<TaskAuditVO> taskAuditVOS = new ArrayList<>();
            setTaskProgress(taskAuditVOS,detailByBase.getTaskAnnualVOS());
            baseBusinessAuditVO.setTaskAuditVOS(taskAuditVOS);
            //重大工程
            baseBusinessAuditVO.setMajorProgressVOS(detailByBase.getMajorProgressVOS());
            //主责主业
            List<MainAuditVO> mainAuditVOS = new ArrayList<>();
            setMainAudit(mainAuditVOS,detailByBase.getMainAnnualVOS());
            baseBusinessAuditVO.setMainAuditVOS(mainAuditVOS);
            //履职成效
            baseBusinessAuditVO.setEffectiveRate(detailByBase.getEffectiveRate());
            baseBusinessAuditVO.setTargetValue(detailByBase.getTargetValue());
            baseBusinessAuditVO.setRemarks(detailByBase.getRemarks());
            baseBusinessAuditVO.setIsMajorProject(detailByBase.getIsMajorProject());
            baseBusinessAuditVO.setModuleType(1);
            //企业自评
            List<AuditAssets> auditAssets = new ArrayList<>();
            setAuditAssets(auditAssets,detailByBase.getSelfAssessments());
            baseBusinessAuditVO.setAuditAssets(auditAssets);
        }else {
            return null;
        }

        return baseBusinessAuditVO;
    }

    @Override
    public void issued(BaseBusinessAudit baseBusinessAudit){
        BaseBusinessAudit byId = getById(baseBusinessAudit.getId());
        BaseBusinessAuditVO baseBusinessAuditVO = baseBusinessAuditWrapper.entityToVO(byId);

        byId.setIssued(1);
        saveOrUpdate(byId);
        //修改年度，是否国资审核
        List<BaseBusinessAnnual> annuals = glcBaseBusinessAnnualService.list(new LambdaQueryWrapper<BaseBusinessAnnual>().eq(BaseBusinessAnnual::getFillingYear, byId.getFillingYear()).eq(BaseBusinessAnnual::getFillingUnitId, byId.getFillingUnitId()));
        if (CollectionUtil.isNotEmpty(annuals)){
            BaseBusinessAnnual baseBusinessAnnual = annuals.get(0);
            baseBusinessAnnual.setIsAudit(1);
            baseBusinessAnnual.setBaseAuditId(byId.getId());
            glcBaseBusinessAnnualService.saveOrUpdate(baseBusinessAnnual);

            Message message = Message.builder().formId(baseBusinessAuditVO.getId()+"").orgName(baseBusinessAuditVO.getFillingUnitName())
                    .orgId(baseBusinessAuditVO.getFillingUnitId()).formType(baseBusinessAuditVO.getFormType()).formTypeName("经营绩效考核国资审核数").messageTime(DateUtil.now())
                    .createUser(baseBusinessAnnual.getCreateUser()).message("经营绩效考核国资审核数").build();
            messageService.save(message);

        }

    }

    /**
     * @Author: Take-off
     * @Description: //TODO 放财务绩效
     * @Date: 10:11 AM 2022/12/19
     * @Param: [baseBusinessAuditVO, businessAuditVOS]
     * @return: void
     **/
    private void setBusinessProgress(List<BusinessAuditVO> businessAuditVOS,List<BusinessAnnualVO> businessAnnualVOS){
        if (CollectionUtil.isNotEmpty(businessAnnualVOS)){
            //放入
            if (CollectionUtil.isNotEmpty(businessAuditVOS)){
                businessAuditVOS.forEach(m -> {
                    List<BusinessAnnualVO> businessAnnualVOList = businessAnnualVOS.stream().filter(index -> m.getBusinessIndicatorsId().equals(index.getBusinessIndicatorsId())).collect(Collectors.toList());
                    if (CollectionUtil.isNotEmpty(businessAnnualVOList)){
                        BusinessAnnualVO vo = businessAnnualVOList.get(0);
                        m.setBusinessIndicatorsId(vo.getBusinessIndicatorsId());
                        m.setIndicatorsCategoryName(vo.getIndicatorsCategoryName());
                        m.setIndicatorsCategoryId(vo.getIndicatorsCategoryId());
                        m.setAnnualSubmit(vo.getAnnualSubmit());
                        if (!Optional.ofNullable(m.getIndicatorsWeight()).isPresent()){
                            m.setIndicatorsWeight(vo.getIndicatorsWeight());
                            m.setBaseline(vo.getBaseline());
                            m.setTarget(vo.getTarget());
                            m.setBasicTarget(vo.getBasicTarget());
                        }
                    }
                });
            }else {
                businessAnnualVOS.forEach(vo -> {
                    BusinessAuditVO businessAuditVO = new BusinessAuditVO();
                    businessAuditVO.setBusinessIndicatorsId(vo.getBusinessIndicatorsId());
                    businessAuditVO.setIndicatorsCategoryName(vo.getIndicatorsCategoryName());
                    businessAuditVO.setIndicatorsWeight(vo.getIndicatorsWeight());
                    businessAuditVO.setBaseline(vo.getBaseline());
                    businessAuditVO.setTarget(vo.getTarget());
                    businessAuditVO.setBasicTarget(vo.getBasicTarget());
                    businessAuditVO.setIndicatorsCategoryId(vo.getIndicatorsCategoryId());
                    businessAuditVO.setAnnualSubmit(vo.getAnnualSubmit());
                    businessAuditVOS.add(businessAuditVO);
                });
            }

        }

    }

    /**
     * @Author: Take-off
     * @Description: //TODO 放任务绩效
     * @Date: 10:14 AM 2022/12/19
     * @Param: [baseBusinessAuditVO, taskIndicatorsVOS]
     * @return: void
     **/
    private void setTaskProgress(List<TaskAuditVO> taskAuditVOS,List<TaskAnnualVO> taskAnnualVOS){
        if (CollectionUtil.isNotEmpty(taskAnnualVOS)){
            if (CollectionUtil.isNotEmpty(taskAuditVOS)){
                for (TaskAuditVO taskAuditVO :taskAuditVOS){
                    List<TaskAnnualVO> taskProgressVOList = taskAnnualVOS.stream().filter(index -> taskAuditVO.getTaskIndicatorsId().equals(index.getTaskIndicatorsId())).collect(Collectors.toList());
                    if (CollectionUtil.isNotEmpty(taskProgressVOList)){
                        TaskAnnualVO vo = taskProgressVOList.get(0);
                        taskAuditVO.setTaskIndicatorsId(vo.getTaskIndicatorsId());
                        taskAuditVO.setIndicatorsCategoryName(vo.getIndicatorsCategoryName());
                        taskAuditVO.setIndicatorsCategoryId(vo.getIndicatorsCategoryId());
                        taskAuditVO.setIndexNum(vo.getIndexNum());
                        taskAuditVO.setContent(vo.getContent());
                        taskAuditVO.setAnnualSummary(vo.getExecution());
                        taskAuditVO.setSelfScoring(vo.getSelfScoring());
                    }
                }
            }else {
                for (TaskAnnualVO vo :taskAnnualVOS){
                    //vo
                    TaskAuditVO taskAuditVO = new TaskAuditVO();
                    taskAuditVO.setTaskIndicatorsId(vo.getTaskIndicatorsId());
                    taskAuditVO.setIndicatorsCategoryName(vo.getIndicatorsCategoryName());
                    taskAuditVO.setIndicatorsCategoryId(vo.getIndicatorsCategoryId());
                    taskAuditVO.setIndexNum(vo.getIndexNum());
                    taskAuditVO.setContent(vo.getContent());
                    taskAuditVO.setAnnualSummary(vo.getExecution());
                    taskAuditVO.setSelfScoring(vo.getSelfScoring());

                    taskAuditVOS.add(taskAuditVO);
                }
            }

        }
    }

    /**
     * @Author: Take-off
     * @Description: //TODO 放主责主业
     * @Date: 10:14 AM 2022/12/19
     * @Param: [baseBusinessAuditVO, taskIndicatorsVOS]
     * @return: void
     **/
    private void setMainAudit( List<MainAuditVO> mainAuditVOS,List<MainAnnualVO> mainAnnualVOS){
        if (CollectionUtil.isNotEmpty(mainAnnualVOS)){
            //VO 表/展示
            if (CollectionUtil.isNotEmpty(mainAuditVOS)){
                for (MainAuditVO mainAuditVO:mainAuditVOS){
                    List<MainAnnualVO> mainAnnualVOList = mainAnnualVOS.stream().filter(index -> mainAuditVO.getMainBusinessId().equals(index.getMainBusinessId())).collect(Collectors.toList());
                    if (CollectionUtil.isNotEmpty(mainAnnualVOList)){
                        MainAnnualVO vo = mainAnnualVOList.get(0);
                        mainAuditVO.setMainBusinessId(vo.getMainBusinessId());
                        mainAuditVO.setIndexNum(vo.getIndexNum());
                        mainAuditVO.setEvaluation(vo.getEvaluation());
                        mainAuditVO.setExecution(vo.getExecution());
                        mainAuditVO.setSelfScore(vo.getSelfScore());
                    }
                }
            }else {
                for (MainAnnualVO vo :mainAnnualVOS){
                    //vo
                    MainAuditVO mainAuditVO = new MainAuditVO();

                    mainAuditVO.setMainBusinessId(vo.getMainBusinessId());
                    mainAuditVO.setIndexNum(vo.getIndexNum());
                    mainAuditVO.setEvaluation(vo.getEvaluation());
                    mainAuditVO.setExecution(vo.getExecution());
                    mainAuditVO.setSelfScore(vo.getSelfScore());

                    mainAuditVOS.add(mainAuditVO);
                }
            }
        }
    }

    private void setAuditAssets( List<AuditAssets> auditAssets,List<SelfAssessment> selfAssessments){
        if (CollectionUtil.isNotEmpty(selfAssessments)){
            //VO 表/展示
            if (CollectionUtil.isNotEmpty(auditAssets)){
                for (AuditAssets assets:auditAssets){
                    List<SelfAssessment> assessments = selfAssessments.stream().filter(index -> assets.getBaseAssessId().equals(index.getId())).collect(Collectors.toList());
                    if (CollectionUtil.isNotEmpty(assessments)){
                        SelfAssessment vo = assessments.get(0);
                        assets.setExecution(vo.getExecution());
                        assets.setSelfScore(vo.getSelfScore());
                        assets.setType(vo.getType());
                    }
                }
            }else {
                for (SelfAssessment vo :selfAssessments){
                    //vo
                    AuditAssets assets = new AuditAssets();
                    assets.setBaseAssessId(vo.getId());
                    assets.setExecution(vo.getExecution());
                    assets.setSelfScore(vo.getSelfScore());
                    assets.setType(vo.getType());

                    auditAssets.add(assets);
                }
            }
        }
    }

}
